In [1]:
import tensorflow as tf
In [3]:
input = tf.placeholder(tf.float32, (None, 32, 32, 3))
filter_weights = tf.Variable(tf.truncated_normal((8, 8, 3, 20))) # (height, width, input_depth, output_depth)
filter_bias = tf.Variable(tf.zeros(20))
strides = [1, 2, 2, 1] # (batch, height, width, depth)
padding = 'SAME'
conv = tf.nn.conv2d(input, filter_weights, strides, padding) + filter_bias
In [4]:
conv
Out[4]:
The padding algorithm Tensorflow uses is not exactly the same as normal padding. More info of how Tensorflow does padding
TensorFlow uses the following equation for 'SAME' vs 'PADDING'
SAME Padding, the output height and width are computed as:
out_height = ceil(float(in_height) / float(strides1))
out_width = ceil(float(in_width) / float(strides[2]))
VALID Padding, the output height and width are computed as:
out_height = ceil(float(in_height - filter_height + 1) / float(strides1))
out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))
In [ ]: